//
//  IFPlayAudioWindow.m
//  IfengNews
//
//  Created by lihongdan on 14-7-10.
//
//

#import "IFPlayAudioWindow.h"
#import "BlockUI.h"
#import "UIView+Utils.h"

@implementation IFPlayAudioWindow

- (instancetype)init{
    self=[super init];
    if(self){
        self.bg=[[UIImageView alloc] init];
        self.bg.userInteractionEnabled=YES;
        self.bg.frame=CGRectMake(0, 0, GlobleWidth, 64.f);
        [self addSubview:self.bg];
       
        
        self.audioView=[[IFAudioView alloc] init];
        //self.audioView.leftLabel.text=@"音频";
        self.frame=CGRectMake(0, 0, GlobleWidth, 64.f);
        [self addSubview:self.audioView];
        [self.audioView checkStatus];
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(self.audioView.slider.right, 10.f, 40.f, 36.f);
        [self addSubview:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            [self.audioView clickPlay];
        }];
        
        self.audioView.leftLogo.hidden=YES;
        self.audioView.slider.frame=CGRectMake(self.audioView.leftLogo.right, 34.f, 211.f, 1.f);
       
        
        
        self.audioView.currentTime.frame=
        CGRectMake(self.audioView.slider.left+2, self.audioView.slider.bottom+4, 30.f, self.audioView.currentTime.font.lineHeight);
     
        self.audioView.totalTime.frame=CGRectMake(self.audioView.slider.right-32.f, self.audioView.slider.bottom+4, 30.f, self.audioView.currentTime.font.lineHeight);
        
        
        
     [self addSubview:self.audioView.slider];
        
        self.close=[UIButton buttonWithType:UIButtonTypeCustom];
        self.close.frame=CGRectMake(13.f, (64.f-28.f)/2.f+2, 28.f, 28.f);
        
        [self addSubview:self.close];
        [self.close handleControlEvent:UIControlEventTouchUpInside withBlock:^(id send){
        
            [[IFAudioPlayerManager shareInstance] stop];
        
        }];
        
         [self updateCSS];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(updateCSS)
                                                     name:@"NightModeDidChangeNotification" object:nil];
        
    }
    return self;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)checkStatus{
    [self.audioView checkStatus];
}

- (void)updateCSS{
   
  
        self.bg.image=[UIImage imageNamed:@"globle_audio_bg.png"];
        [self.close setImage:[UIImage imageNamed:@"globle_audio_close.png"] forState:UIControlStateNormal];
   
    [self.audioView updateCss];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
